/*
 * 地图加载图标方法
 */
const loadIcon = function (data) {
  const modelsGreen = []; //模型数组
  let allVisible = false; //默认设置可见
  for (let i = 0; i < data.destination.length; i++) {
    //循环创建标志
    var optMark = {
      position: data.destination[i], //坐标
      url: data.url instanceof Array ? data.url[i][0] : data.url, //icon地址
      scale: 1,
      labelfill: "rgba(255,255,255,1)",
      labelfont: "10px 宋体",
      labeloffset: [20, 0],
      visibleHeight: [0, 240000],
      scaleByDistance: [14000, 1, 24000, 0.7],
      description: {
        //鼠标点击判断标志
        type: data.type,
        id: data.id[i],
        position: data.destination[i],
      },
    };
    var mark = new CgsMark(optMark);
    mark.feature3D.entity.billboard.disableDepthTestDistance =
      Number.MAX_SAFE_INTEGER;
    mark.feature3D.label.entity.label.disableDepthTestDistance =
      Number.POSITIVE_INFINITY; // label不被地形遮挡
    map.addFeature(mark);
    modelsGreen.push(mark);
  }

  function setVisible(visible) {
    allVisible = visible;
    for (let i = 0; i < modelsGreen.length; i++) {
      modelsGreen[i].setVisible(allVisible);
    }
  }
  return {
    setVisible: setVisible,
  };
};
export default loadIcon;
